﻿@{
    ViewBag.Title = "工作项目管理";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

<script>
    var _typeId = "";
    var _BillType = request('BillType');
    var _organizeId = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId";
    $(function () {
        InitialPage();
        GetTree();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 171.5);
            }, 200);
            e.stopPropagation();
        });

    }

    function GetTree() {
        var _url = "";
        if (_BillType == "1") {//开店
            _url = "../../DailyEventManage/OpenShop/GetDataItemTreeJson?EnCode=OpenShopWorkType";
        }
        else if (_BillType == "2") {//闭店
            _url = "../../DailyEventManage/OpenShop/GetDataItemTreeJson?EnCode=CloseShopWorkType";
        }
        else {
            _url = "";
        }
        var item = {
            url: _url,
            onnodeclick: function (item) {
                _typeId = item.id;
                $('#btn_Search').trigger("click");
            }
        };
        //初始化
        $("#itemTree").treeview(item);
    }



    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var queryJson = new Object();
        queryJson["OrganizeId"] = _organizeId;
        queryJson["TypeId"] = _typeId;
        queryJson["Category"] = _BillType;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../DailyEventManage/OpenShop/GetShopItemPageListJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 171.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", index: "Id", hidden: true },
                { label: "项目编号", name: "Code", index: "Code", width: 150, align: "center" },
                { label: "项目名称", name: "Name", index: "Name", width: 150, align: "center" },
                { label: "工作类型", name: "ItemName", index: "ItemName", width: 100, align: "center" },
                { label: "责任部门", name: "FullName", index: "FullName", width: 100, align: "center" },
                { label: "工作标准", name: "Criterion", index: "Criterion", width: 150, align: "center" }
            ],
            rownumbers: true,
            sortname: 'Code',
            sortorder: 'desc',
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            },
            subGrid: true,
            subGridRowExpanded: function (subgrid_id, row_id) {
                var _itemId = $("#gridTable").jqGrid('getRowData', row_id)['Id'];
                var subgrid_table_id = subgrid_id + "_t";
                var subhtml = "";
                subhtml += '<div><table id="' + subgrid_table_id + '"></table></table></div>';
                $("#" + subgrid_id).html(subhtml);
                $("#" + subgrid_table_id).jqGrid({
                    datatype: "json",
                    url: " ../../DailyEventManage/OpenShop/GetItemObject?ItemId=" + _itemId,
                    unwritten: false,
                    colModel: [
                       { label: "Id", name: "Id", hidden: true },
                       {
                           label: "类别", name: "ObjectTypeId", width: 120, idnex: "ObjectTypeId", align: "center", sortable: false,
                           formatter: function (cellvalue, options, rowObject) {
                               switch (cellvalue) {
                                   case 0: return "房间"; break;
                                   case 1: return "商户"; break;
                                   case 2: return "公共部位"; break;
                                   case 3: return "设备"; break;
                                   case 4: return "装修现场"; break;
                                   case 5: return "内容"; break;
                                   default: return ""; break;
                               }
                           }
                       },
                       { label: "名称", name: "ObjectName", width: 120, idnex: "ObjectName", align: "center", sortable: false },
                       {
                           label: "是否需要附件", name: "PictureFlag", width: 120, idnex: "PictureFlag", align: "center", sortable: false,
                           formatter: function (cellvalue, options, rowObject) {
                               return cellvalue == 1 ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                           },
                       },
                       { label: "ObjectId", name: "ObjectId", hidden: true },
                       { label: "ItemId", name: "ItemId", hidden: true },
                       { label: "ContentId", name: "ContentId", hidden: true }
                    ],
                    rowNum: 1000,
                    rownumbers: true,
                    shrinkToFit: false,
                    gridview: true,
                    hidegrid: false
                });
            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = new Object();
            queryJson["OrganizeId"] = _organizeId;
            queryJson["TypeId"] = _typeId;
            queryJson["Category"] = _BillType;
            queryJson["condition"] = $("#queryCondition").find('.dropdown-text').attr('data-value');
            queryJson["keyword"] = $("#txt_Keyword").val();
            $gridTable.jqGrid('setGridParam', {
                url: "../../DailyEventManage/OpenShop/GetShopItemPageListJson",
                postData:{ queryJson: JSON.stringify(queryJson) }
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    //新增
    function btn_add() {
        dialogOpen({
            id: "Form1",
            title: '添加工作项目',
            url: '/DailyEventManage/OpenShop/ItemForm?BillType=' + _BillType,
            width: "1100px",
            height: "850px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }

    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form1",
                title: '编辑工作项目',
                url: '/DailyEventManage/OpenShop/ItemForm?keyValue=' + keyValue + "&BillType=" + _BillType,
                width: "1100px",
                height: "850px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }
    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: "../../DailyEventManage/OpenShop/ItemRemoveForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").resetSelection();
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的项目！', 0);
        }
    }

    //巡检项目类别
    function btn_PollingItemcategory() {
        dialogOpen({
            id: "DataItemSort",
            title: '巡检项目分类',
            url: '/PropertyManage/CS_Polling/ItemIndex',
            width: "800px",
            height: "500px",
            btn: null
        });
    }

    //保存表单
    function AcceptClick() {
        dialogClose();
    }

</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel" style="height:97.5%;">
            <div class="panel-Title">工作类型</div>
            <div id="itemTree"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="panel-Title">工作项目信息</div>
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>
                                <div id="queryCondition" class="btn-group">
                                    <a class="btn btn-default dropdown-text" data-toggle="dropdown">选择条件</a>
                                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a data-value="Code">编号</a></li>
                                        <li><a data-value="Name">名称</a></li>
                                    </ul>
                                </div>
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-addItem" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-editItem" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-deleteItem" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>
